package com.heima.common.exception;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Configuration
@Slf4j
public class GlobalExceptionHandle {

    @ExceptionHandler(Exception.class)
    public ResponseResult exception(Exception ex){
        log.error("catch exception:{}", ex.getMessage());
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

    @ExceptionHandler(ProjectExcpetion.class)
    public ResponseResult exception(ProjectExcpetion ex){
        log.error("catch exception:{} msg:{}", ex.getMessage() , ex.getAppHttpCodeEnum().getErrorMessage());
        return ResponseResult.errorResult(ex.getAppHttpCodeEnum());
    }

}
